package de.fhhof.robot.control.cmd;

import de.fhhof.robot.control.IMessage;
import de.fhhof.robot.control.MessageIdGenerator;
import de.fhhof.robot.control.cmd.concreate.CmdAbortAssemblyProcess;
import de.fhhof.robot.control.cmd.concreate.CmdGenericError;
import de.fhhof.robot.control.cmd.concreate.CmdNewAssemblyProcess;
import de.fhhof.robot.control.cmd.concreate.CmdRequestSmarties;
import de.fhhof.robot.control.common.MessageUtility;
import de.fhhof.robot.control.impl.ControlToJsap;
import de.fhhof.robot.control.impl.ControlToRobot;
import de.fhhof.robot.control.impl.ControlToStorage;

public class SAPCommandFactory {

	private static AbstractCommand assemblyCommand = null;
	
	public static AbstractCommand createCommand(IMessage message){
		
		AbstractCommand cmd = null;
		
		if(message.getCommand().equals("K000")){
			cmd = new CmdNewAssemblyProcess(new ControlToRobot(), new ControlToStorage(), new ControlToJsap());
			cmd.setCmdId(System.currentTimeMillis());
		}
		else if(message.getCommand().equals("K001")){
			cmd = new CmdRequestSmarties(new ControlToStorage());
		}
		else if(message.getCommand().equals("K002")){
			cmd = new CmdAbortAssemblyProcess();
		}
		else{
			cmd = new CmdGenericError();
		}
		cmd.setMessage(message);
		
		return cmd;
	}

	public static AbstractCommand getCurrentAssemblyCommand(){
		return assemblyCommand;
	}
	public static synchronized void resetCurrentAssemblyCommand(){
		assemblyCommand = null;
	}
	public static synchronized void setRunningAssemblyCommand(AbstractCommand cmd){
		assemblyCommand = cmd;
	}
}
